home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Internet / WWW / Perl_WWW_Utilities / perlMIF_beta2 / mif / mif_elem.pl < prev    next >
Encoding:
Perl Script  |  1994-05-18  |  6.3 KB  |  179 lines

  1. ##---------------------------------------------------------------------------##
  2. ##  File:
  3. ##      mif_elem.pl
  4. ##  Author:
  5. ##      Earl Hood       ehood@convex.com
  6. ##  Description:
  7. ##    This file is defines the "mif_elem" perl package.  It defines
  8. ##    routines to handle ElementBegin/End via MIFread_mif() defined in
  9. ##    the "mif" package.
  10. ##---------------------------------------------------------------------------##
  11. ##  Copyright (C) 1994  Earl Hood, ehood@convex.com
  12. ##
  13. ##  This program is free software; you can redistribute it and/or modify
  14. ##  it under the terms of the GNU General Public License as published by
  15. ##  the Free Software Foundation; either version 2 of the License, or
  16. ##  (at your option) any later version.
  17. ## 
  18. ##  This program is distributed in the hope that it will be useful,
  19. ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. ##  GNU General Public License for more details.
  22. ##  
  23. ##  You should have received a copy of the GNU General Public License
  24. ##  along with this program; if not, write to the Free Software
  25. ##  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  26. ##---------------------------------------------------------------------------##
  27.  
  28. require 'mif/mif.pl' || die "Unable to require mif.pl\n";
  29.  
  30. package mif_elem;
  31.  
  32. ##--------------------------------------##
  33. ## Add Font routines to %MIFToken array ##
  34. ##--------------------------------------##
  35. $mif'MIFToken{'ElementBegin'} = 'ElementBegin';
  36. $mif'MIFToken{'ElementEnd'} = 'ElementEnd';
  37. $mif'MIFToken{'ETag'} = "mif_elem'ETag";
  38. $mif'MIFToken{'Collapsed'} = "mif_elem'Collapsed";
  39. $mif'MIFToken{'SpecialCase'} = "mif_elem'SpecialCase";
  40.  
  41. ##--------------------##
  42. ## mif_elem variables ##
  43. ##--------------------##
  44. $eb_func = "";    # Function to call during ElementBegin closure.
  45. $ee_func = "";    # Function to call when ElementEnd occurs (passed tagstring)
  46.  
  47. ##-----------------------------------------------##
  48. ## Variables for current ElementBegin definition ##
  49. ##-----------------------------------------------##
  50. $ETag            = "";
  51. $Collapsed        = "";
  52. $SpecialCase        = "";
  53.  
  54. ##------------------------##
  55. ## Import 'mif' variables ##
  56. ##------------------------##
  57. $MStore        = $mif'MStore;
  58. $MOpen        = $mif'MOpen;
  59. $MClose        = $mif'MClose;
  60. $MLine        = $mif'MLine;
  61. $mso        = $mif'mso;
  62. $msc        = $mif'msc;
  63. $stb        = $mif'stb;
  64. $ste        = $mif'ste;
  65. $como        = $mif'como;
  66.  
  67.                 ##---------------##
  68.                 ## Main Routines ##
  69.                 ##---------------##
  70. ##---------------------------------------------------------------------------
  71. ##    MIFget_elem_funcs() returns the functions that are called for
  72. ##    ElementBegin and ElementEnd statements.
  73. ##
  74. ##    Usage:
  75. ##        ($beginfunc, $endfunc) = &'MIFget_elem_funcs();
  76. ##
  77. sub main'MIFget_elem_funcs {
  78.     ($eb_func, $ee_func);
  79. }
  80. ##---------------------------------------------------------------------------
  81. ##    MIFset_elem_funcs() sets the functions that are called for
  82. ##    ElementBegin and ElementEnd statements.
  83. ##
  84. ##    Usage:
  85. ##        &'MIFset_elem_funcs($beginfunc, $endfunc);
  86. ##
  87. sub main'MIFset_elem_funcs {
  88.     ($eb_func, $ee_func) = @_;
  89. }
  90. ##---------------------------------------------------------------------------
  91. ##    MIFwrite_elem_beg() outputs the ElementBegin in MIF.
  92. ##
  93. ##    Usage:
  94. ##        &'MIFwrite_elem_beg(FILEHANDLE,$indent,$tag,$collapsed,$specase);
  95. ##
  96. sub main'MIFwrite_elem_beg {
  97.     local($handle, $l, $tag, $collapsed, $specase) = @_;
  98.     local($i0, $i1, $i2) = (' ' x $l, ' ' x (1+$l), ' ' x (2+$l));
  99.  
  100.     print $handle $i0, $mso, "ElementBegin\n";
  101.     print $handle $i1, $mso, 'ETag ', $stb, $tag, $ste, $msc, "\n";
  102.     print $handle $i1, $mso, 'Collapsed ', $collapsed, $msc, "\n"
  103.     if $collapsed ne "";
  104.     print $handle $i1, $mso, 'SpecialCase ', $specase, $msc, "\n"
  105.     if $SpecialCase ne "";
  106.     print $handle $i0, $msc, " $como end of ElementBegin\n";
  107. }
  108. ##---------------------------------------------------------------------------##
  109. ##    MIFwrite_elem_end() outputs ElementEnd in MIF.
  110. ##
  111. ##    Usage:
  112. ##        &'MIFwrite_elem_end(FILEHANDLE, $indent, $tag);
  113. ##
  114. sub main'MIFwrite_elem_end {
  115.     local($handle, $l, $tag);
  116.     local($i0) = (' ' x $l);
  117.     local($tmp) = (($tag ne "" ? $stb.$tag.$ste : ""));
  118.     print $handle $i0, $mso, 'ElementEnd ', $tmp, $msc, "\n";
  119. }
  120. ##---------------------------------------------------------------------------##
  121. ##    MIFget_last_elem_beg() is a convienence routine that returns the
  122. ##    data associated with the last ElementBegin statement.  This routine
  123. ##    is mainly used by other mif_* libraries that need to process
  124. ##    ElementBegin statements.
  125. ##
  126. ##    Usage:
  127. ##        ($tag, $collapsed, $specase) = &'MIFget_last_elem_beg();
  128. ##
  129. sub main'MIFget_last_elem_beg {
  130.     ($ETag, $Collapsed, $SpecialCase);
  131. }
  132. ##---------------------------------------------------------------------------##
  133.                 ##--------------##
  134.                 ## Mif Routines ##
  135.                 ##--------------##
  136. ##---------------------------------------------------------------------------##
  137. ##    The routines definded below are all registered in the %MIFToken         ##
  138. ##    array for use in the MIFread_mif() routine.  There purpose is to     ##
  139. ##    store the information contained in ElementBegin/End statements.         ##
  140. ##---------------------------------------------------------------------------##
  141.  
  142. ##---------------------------------------------------------------------------
  143. sub mif'ElementBegin {
  144.     local($token, $mode, *data) = @_;
  145.  
  146.     if ($mode == $MOpen) {
  147.     $ETag        = "";
  148.     $Collapsed    = "";
  149.     $SpecialCase    = "";
  150.     } elsif ($mode == $MClose) {
  151.     &$eb_func() if $eb_func;
  152.     } else {
  153.     warn "Unexpected mode, $mode, passed to ElementBegin routine\n";
  154.     }
  155. }
  156. ##---------------------------------------------------------------------------
  157. sub mif'ElementEnd {
  158.     local($token, $mode, *data) = @_;
  159.     $data =~ /^\s*$stb([^$ste]*)$ste.*$/o;
  160.     &$ee_func($1) if $ee_func;
  161. }
  162. ##---------------------------------------------------------------------------
  163. sub ETag {
  164.     local($token, $mode, *data) = @_;
  165.     ($ETag) = $data =~ /^\s*$stb([^$ste]*)$ste.*$/o;
  166. }
  167. ##---------------------------------------------------------------------------
  168. sub Collapsed {
  169.     local($token, $mode, *data) = @_;
  170.     ($Collapsed) = $data =~ /^\s*(.*)$/o;
  171. }
  172. ##---------------------------------------------------------------------------
  173. sub SpecialCase {
  174.     local($token, $mode, *data) = @_;
  175.     ($SpecialCase) = $data =~ /^\s*(.*)$/o;
  176. }
  177. ##---------------------------------------------------------------------------
  178. 1;
  179.